package com.asset.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;


import com.asset.common.annotation.Log;
import com.asset.common.core.controller.BaseController;
import com.asset.common.core.domain.R;
import com.asset.common.enums.BusinessType;
import com.asset.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.asset.manage.domain.Classify;
import com.asset.manage.service.IClassifyService;


/**
 * 资产分类Controller
 *
 * @author mobin
 * @date 2024-08-24
 */
@Api(tags = "资产分类")
@RestController
@RequestMapping("/manage/classify")
public class ClassifyController extends BaseController {
    @Autowired
    private IClassifyService classifyService;

    /**
     * 查询资产分类列表
     */
    @ApiOperation("查询资产分类列表")
    @PreAuthorize("@ss.hasPermi('manage:classify:list')")
    @GetMapping("/list")
    public R<List<Classify>> list(Classify classify) {
        List<Classify> list = classifyService.selectClassifyList(classify);
        return R.ok(list);
    }

    /**
     * 导出资产分类列表
     */
    @ApiOperation("导出资产分类列表")
    @PreAuthorize("@ss.hasPermi('manage:classify:export')")
    @Log(title = "资产分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Classify classify) {
        List<Classify> list = classifyService.selectClassifyList(classify);
        ExcelUtil<Classify> util = new ExcelUtil<Classify>(Classify.class);
        util.exportExcel(response, list, "资产分类数据");
    }

    /**
     * 获取资产分类详细信息
     */
    @ApiOperation("获取资产分类详细信息")
    @PreAuthorize("@ss.hasPermi('manage:classify:query')")
    @GetMapping(value = "/{id}")
    public R<Object> getInfo(@PathVariable("id") Long id) {
        return R.ok(classifyService.selectClassifyById(id));
    }

    /**
     * 新增资产分类
     */
    @ApiOperation("新增资产分类")
    @PreAuthorize("@ss.hasPermi('manage:classify:add')")
    @Log(title = "资产分类", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Object> add(@RequestBody Classify classify) {
        return R.ok(classifyService.insertClassify(classify));
    }

    /**
     * 修改资产分类
     */
    @ApiOperation("修改资产分类")
    @PreAuthorize("@ss.hasPermi('manage:classify:edit')")
    @Log(title = "资产分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Object> edit(@RequestBody Classify classify) {
        return R.ok(classifyService.updateClassify(classify));
    }

    /**
     * 删除资产分类
     */
    @ApiOperation("删除资产分类")
    @PreAuthorize("@ss.hasPermi('manage:classify:remove')")
    @Log(title = "资产分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Object> remove(@PathVariable Long[] ids) {
        return R.ok(classifyService.deleteClassifyByIds(ids));
    }
}
